#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
ll gcd(ll a,ll b){
	if(a<b)swap(a,b);
	return (a==b)?a:((a%2==0)?((b%2==0)?2*gcd(a/2,b/2):gcd(a/2,b)):((b%2==0)?gcd(a,b/2):gcd(b,a-b)));
}
struct num{
    ll s,m;
};
struct car{
    num s,e;
}c[N];
bool operator> (num a,num b){
    return (a.s*b.m)>(b.s*a.m);
}
bool operator== (num a,num b){
    return (a.s*b.m)==(b.s*a.m);
}
bool operator< (num a,num b){
    return (a.s*b.m)<(b.s*a.m);
}
bool operator>= (num a,num b){
    return (a.s*b.m)>=(b.s*a.m);
}
bool operator<= (num a,num b){
    return (a.s*b.m)<=(b.s*a.m);
}
bool operator> (car a,car b){
    return (a.s==b.s)?(a.e>b.e):(a.s>b.s);
}
bool operator< (car a,car b){
    return (a.s==b.s)?(a.e<b.e):(a.s<b.s);
}
bool operator== (car a,car b){
    return (a.s==b.s)&&(a.e==b.e);
}
void gnum(num &a){
    ll g=gcd(a.s,a.m);
    a.s/=g;
    a.m/=g;
}
num gadd(num a,num b){
    num c;
    c.m=a.m*b.m;
    c.s=a.m*b.s+a.s*b.m;
    gnum(c);
    return c;
}
ll n,m,L,V;
num cks[N];
ll ttmp1[N],ttmp2[N],tcnt1,tcnt2;
bool check(){
    sort(ttmp1,ttmp1+tcnt1);
    sort(ttmp2,ttmp2+tcnt2);
    //if(tcnt1!=tcnt2)return 1;
    for(int i=0;i<min(tcnt1,tcnt2);i++){
        if(ttmp1[i]!=ttmp2[i])return 0;
    }
    if(tcnt1<=tcnt2)return 1;
    return 0;
}
void tot(){
    tcnt2=tcnt1;
    for(int i=0;i<tcnt1;i++){
        ttmp2[i]=ttmp1[i];
        ttmp1[i]=0;
    }
    tcnt1=0;
}
void init(){
    memset(ttmp1,0,sizeof(ttmp1));
    memset(ttmp2,0,sizeof(ttmp2));
    tcnt1=tcnt2=0;
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin.tie(0),cout.tie(0);
    ios::sync_with_stdio(0);
    ll T=1;
    cin>>T;
    while(T--){
        cin>>n>>m>>L>>V;
        num cart;
        cart.m=1;
        cart.s=0;
        for(int i=0;i<=n;i++){
            c[i].e=c[i].s=cart;
        }
        for(int i=0;i<=m;i++){
            cks[i]=cart;
        }
        for(int i=1;i<=n;i++){
            ll a,v0,d;
            cin>>d>>v0>>a;
            if(a<=0&&v0<=V){
                i--;
                n--;
                continue;
            }
            if(a>=0&&v0>V){
                c[i].s.s=d;
                c[i].s.m=1;
                c[i].e.s=L;
                c[i].e.m=1;
                continue;
            }
            if(a<0){
                c[i].s.s=d;
                c[i].s.m=1;
                c[i].e.s=v0*v0-V*V;
                c[i].e.m=0-a*2;
                gnum(c[i].e);
                c[i].e=gadd(c[i].e,c[i].s);
                num t;
                t.s=L;
                t.m=1;
                c[i].e=min(c[i].e,t);
            }
            else {
                c[i].s.s=V*V-v0*v0;
                c[i].s.m=2*a;
                c[i].e.s=L;
                c[i].e.m=1;
                num t;
                t.m=1;
                t.s=d;
                gnum(c[i].s);
                c[i].s=gadd(c[i].s,t);
                t.s=L;
                if(c[i].s>t){
                    i--,n--;
                    continue;
                }
            }
        }
        sort(c+1,c+n+1);
        //cout<<"1end"<<'\n';
        //for(int i=1;i<=n;i++){
        //    cout<<c[i].s.s<<"/"<<c[i].s.m<<" "<<c[i].e.s<<"/"<<c[i].e.m<<'\n';
        //}
        for(int i=1;i<=m;i++){
            ll t;
            cin>>t;
            cks[i].s=t;
            cks[i].m=1;
        }
        //cout<<"2end"<<'\n';
        //sort(cek+1,cek+m+1);
        ll ans1=0,ans2=0,j;
        //cout<<'\n';
        for(int i=1,j=1;i<=m,j<=n;i++){
            //if(c[j].s<=cks[i]&&c[j].e>=cks[i]&&j<=n&&(j<=1||(j>1&&cks[i]>c[j-1].e)))ans2++;
            while(c[j].s<=cks[i]&&c[j].e>=cks[i]&&j<=n){
                ans1++;
                j++;
            }
            while(c[j].e<cks[i])j++;
        }
        init();
        for(int i=1;i<=m;i++){
            j=1;
            while(c[j].e<cks[i]&&j<=n)j++;
            while(c[j].s<=cks[i]&&c[j].e>=cks[i]&&j<=n){
                ttmp1[tcnt1++]=j;
                j++;
            }
            if(check()){
                m--;
            }
            tot();
        }
        //if(check()){
        //    m--;
        //}
        cout<<ans1<<" "<<m<<'\n';
    }
    return 0;
}
